package grp.test.service.Impl;

import grp.test.dao.BorrowMapper;
import grp.test.pojo.Book;
import grp.test.dao.BookMapper;
import grp.test.pojo.Borrow;
import grp.test.pojo.BorrowKey;
import grp.test.service.IReturnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Service("iReturnService")
public class IReturnImpl implements IReturnService{
    @Autowired(required=false)
    private BorrowMapper borrowmapper;
    @Autowired(required=false)
    private BookMapper bookmapper;
    @Override
    public Borrow getBorrowInformation(BorrowKey user) {
        Borrow obj = borrowmapper.selectByPrimaryKey(user);
        if(obj == null){
            return null;
        }
        return obj;
    }//查询信息
    @Override
    public List<String> ReturnBook(Integer bookId,Integer userId){
        Date backDateReal = new Date();
        List<String> result=new ArrayList<>();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.format(backDateReal);
        Calendar calendar= Calendar.getInstance();
        calendar.setTime(backDateReal);

        Book bookobj = bookmapper.selectByPrimaryKey(bookId);
        bookobj.setStore(bookobj.getStore()+1);
        result.add("return successful");

        return result;
    }//还书，在borrow表中修改归还时间，在book表中增加库存

}
